package com.sigmazero13.MKDummy.models;

import com.sigmazero13.MKDummy.listeners.PlayerListener;



public class VolkarePlayer extends DummyPlayer {
	
	private static final long serialVersionUID = -3863432627849662325L;
	
	transient private ManaDie die;

	public VolkarePlayer(Integer numWounds) {
		super(MKCharacter.VOLKARE.getName());
		
		for (int i = 0; i < numWounds; i++) {
			getDeck().addNewCard(new Card(ManaColor.WOUND));
		}
		
		getDeck().addNewCard(new Card(ManaColor.RED, true));
		getDeck().addNewCard(new Card(ManaColor.BLUE, true));
		getDeck().addNewCard(new Card(ManaColor.GREEN, true));
		getDeck().addNewCard(new Card(ManaColor.WHITE, true));
		getDeck().reshuffle();
	}
	
	
	@Override
	public void takeTurn() {
		logMessage(" ");
		if (showTimestamp) {
			logMessage("#i#" + getTimeStamp() + "#i#");
		}
		logMessage("#b#Round " + roundNum + ", turn " + turnNum + " summary:#b#");
		turnNum++;
		Card drawn = getDeck().drawCard();
		if (drawn == null) {
			logMessage("#b##XX#FRENZY#XX##b#");
		} else {
			String extra = drawn.isSpell()?"Spell":"";
			StringBuilder message = new StringBuilder();
			message.append("Card drawn: ");
			message.append(drawn.getColor().toColorString(extra));
			
			if (drawn.getColor().equals(ManaColor.WOUND)) {
				message.append(" (Mana die: ");
				message.append(getDie().rollDie().toColorString());
				message.append(")");
			}
			logMessage(message);
		}
		for (PlayerListener listener : getListeners()) {
			listener.onDeckChanged(getDeck());
		}
		flushLogBuffer();
	}
	

	@Override
	public void newRound(ManaColor newCard, ManaColor newCrystal) {
		roundNum++;
		turnNum=1;
		logMessage(" ");
		if (showTimestamp) {
			logMessage("#i#" + getTimeStamp() + "#i#");
		}
		logMessage("#b#New round! (" + roundNum + ")#b#");
		
		refreshListeners();
		flushLogBuffer();
	}
	
	
	private ManaDie getDie() {
		if (die == null) {
			die = new ManaDie();
		}
		return die;
	}
}
